var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    page: 1,
    total_page: 1,


    stock_id: null,
    mobile: null,
    nums: null,
    show: false,
    cate_name: "",
    imgPath: app.globalData.imgPath,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  show_overlay(e) {
    this.setData({
      stock_id: e.currentTarget.dataset.id,
      show: true
    })
  },
  onClickHide() {
    this.setData({
      show: false
    })
  },
  onSearch(event) {
    this.setData({
      cate_name: event.detail
    });
    this.getData({
      cate_name: event.detail,
      page: 1
    });
  },
  link(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/packageI/store_cloud_inventory/list/list?id=' + id,
    })
  },
  InputHandle(e) {
    let type = e.currentTarget.dataset.type;
    this.setData({
      [type]: e.detail.value
    })
  },
   confirm() {
    let json = {
      stock_id: this.data.stock_id,
      mobile: this.data.mobile,
      nums: this.data.nums
    }
    app._postNetWork({
      url: app.getNetAddresss('plugin.store-cloud-stock.frontend.controllers.home.trans'),
      data: json,
      success: resdata => {
        let {
          result,
          msg
        } = resdata.data;
        if (result == 0) {
          return app.tips(msg)
        }
        this.setData({
          show: false
        })
        app.tips(msg)
      }
    })
  },
  getMoreData() {
    if (this.data.page >= this.data.total_page) {
      return;
    }
    let json = {};
    let page = this.data.page + 1;
    json.page = page;
    if (this.data.cate_name) {
      json.cate_name = this.data.cate_name;
    }
    this.getData(json)
  },
   getData(json = {}) {
    app._getNetWork({
      url: app.getNetAddresss('plugin.store-cloud-stock.frontend.controllers.home.index'),
      data: json,
      success: resdata => {
        let {
          result,
          msg,
          data: {
            data,
            current_page,
            last_page
          }
        } = resdata.data;
        if (result == 0) {
          return app.tips(msg)
        }
        this.setData({
          page: current_page,
          total_page: last_page
        })

        if (current_page == 1) {
          this.setData({
            list: data || []
          })
        } else {
          this.setData({
            list: this.data.list.concat(data)
          })
        }
      }
    })

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getMoreData()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})